{% extends 'layout.html' %}


{% block content %}

    <div class="container">
        <div class="panel panel-default">
            <div class="panel-heading">表单</div>
            <div class="panel-body">
                <form id="formAdd">
                    <div class="clearfix">
                        {% for field in form %}
                            <div class="col-xs-6">
                                <div class="form-group">
                                    <label>{{ field.label }}</label>
                                    {{ field }}
                                    <span style="color: red;">{{ field.errors.0 }}</span>
                                </div>
                            </div>
                        {% endfor %}
                        <div class="col-xs-12">
                            <button id="btnAdd" type="button" class="btn btn-primary">提交</button>
                        </div>
                    </div>

                </form>
            </div>
        </div>

    </div>

{% endblock %}

{% block js %}
    <script type="text/javascript">
        $(function () {
            bindBtnAdd();
        })

        function bindBtnAdd(){
            $("#btnAdd").click(function (){
                $.ajax({
                    url: '/task/add/',
                    type: "post",
                    dataType: 'JSON',
                    data: $("#formAdd").serialize(),
                    success: function (res){
                        console.log(res);
                    }
                })
            })
        }

    </script>

{% endblock %}